/*
 * @Descripttion:
 * @version:
 * @Author: kl2018
 * @Date: 2019-03-07 20:06:20
 * @LastEditors: kl2018
 * @LastEditTime: 2020-08-11 16:25:49
 */
import { WeaSwitch } from 'comsMobx';
import { WeaSearchGroup, WeaFormItem } from 'ecCom';

export default function AdSearches(compstore, onSearch) {
  const conditioninfo = compstore.conditioninfo;
  const { adSearchForm } = compstore;
  const { isFormInit } = adSearchForm;
  let group = [];
  isFormInit && conditioninfo.map((c, index) => {
    let items = [];
    c.items && c.items.map((fields) => {
      if (!fields) {
        return;
      }
      items.push({
        com: (
          <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@g3gxyg@${fields.domkey[0]}`}
            label={`${fields.label}`}
            labelCol={{ span: `${fields.labelcol}` }}
            ratio1to2
            error={adSearchForm.getError(fields)}
            tipPosition="bottom"
            wrapperCol={{ span: `${fields.fieldcol}` }}
          >
            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@c9akvn@${fields.domkey[0]}`} fieldConfig={fields} form={adSearchForm} onEnterSearch={() => typeof onSearch == 'function' && onSearch()} />
          </WeaFormItem>

        ),
        colSpan: 1,
      });
    });
    group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@selw5o@${index}`} needTigger={true} title={c.title} showGroup={c.defaultshow} items={items} />);
  });
  return group;
}
